@extends('layout.default')

@section('layout.content')

  <div class="row">
    <div class="col-xs-12">
      <form method="get" action="{{route('point.gift.list',['order'=>$order])}}" class="form-horizontal">
        <div class="space-12"></div>
        <div class="col-xs-12 col-md-6 col-md-offset-3">
          <div class="form-group">
            <div class="input-group">
              <input type="text" value="{{Request::get('query')}}" class="form-control input-lgr" id="query" name="query" maxlength="13" placeholder="帐号" autocomplete="off"/>
              @if(!empty($user))
                <input type="hidden" name="uid" value="{{$user->id}}"/>
              @endif
              <span class="input-group-btn">
                <button class="btn btn-lg btn-primary" id="btn-sign" type="submit">
                  <i class="ace-icon fa fa-search"></i>
                  信息确认
                </button>            
              </span>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div><!-- /.row -->

  @if(!empty($user))
    <div class="row">
      <div class="col-xs-12">
        <table id="user-list" class="table table-hover table-striped table-bordered nonborder">
          <thead>
          <tr>
            <th class="center">帐号</th>
            <th class="align-middle">姓名</th>
            <th class="center">签到</th>
            <th class="hidden-480 center">借阅</th>
            <th class="hidden-480 center">还书</th>
            <th class="center">积分</th>
            <th class="hidden-480 center">手机号码</th>
            <th class="hidden-480 center">登记日期</th>
            <th class="center">签到</th>
            <th class="hidden-480 center">奖励</th>
          </tr>
          </thead>
          <tbody>

          <tr>
            <td class="center smaller-80">
              <a href="{{route('user.edit',array('uid'=>$user->id))}}">{{ $user->account }}</a>
            </td>
            <td class="align-middle">
              <a href="{{route('user.view',array('uid'=>$user->id))}}" class="uid" data-id="{{ $user->id }}">{{ $user->name }}</a>
            </td>
            <td class="center b-sign">{{ $user->summary->signs }}</td>
            <td class="hidden-480 center b-borrow">{{ $user->summary->borrows }}</td>
            <td class="hidden-480 center b-return">{{ $user->summary->returns }}</td>
            <td class="center b-point">{{ $user->summary->points }}</td>
            <td class="hidden-480 center">{{ $user->mobile }}</td>
            <td class="center smaller-80">{{ date('Y-m-d',$user->created_at) }}</td>
            <td class="center">{!! $user->present()->sign !!}</td>
            <td class="hidden-480 center">{!! $user->present()->award !!}</td>
          </tr>

          </tbody>
        </table>
      </div>
    </div>
  @endif
  <div class="space-12"></div>
  <div class="row">
    <div class="col-xs-12">

      <div class="gift-order pull-right hidden-480">
        <label>排序：</label>
        <a href="{{route('point.gift.list',['order'=>'price','query'=>$query])}}"
           class="btn btn-primary {{Request::get('order')=='price'?'active focus':''}}">
          <span class="">兑换积分</span>
        </a>
        <a href="{{route('point.gift.list',['order'=>'exchanged','query'=>$query])}}"
           class="btn btn-primary {{Request::get('order')=='exchanged'?'active focus':''}}">
          <span class="">兑换数</span>
        </a>
        <a href="{{route('point.gift.list',['query'=>$query])}}"
           class="btn btn-primary {{Request::get('order')==''?'active focus':''}}">
          <span class="">更新时间</span>
        </a>
      </div>

    </div>
  </div>

  <div class="space-12"></div>

  <div class="row">
    <div class="col-xs-12 col-md-4">
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
        <tr>
          <th class="center" style="width:30px;"> </th>
          <th class="center" style="width:55px;">图片</th>
          <th class="align-middle">礼品名称</th>
          <th class="center" style="width:45px;">积分</th>
          <th class="center" style="width:45px;">已兑</th>
        </tr>
        </thead>
        <tbody>          
          @foreach ($gifts as $i=>$gift)   
          <?php
              if($i == $paging) break;
              $gift = $gifts->shift();
          ?>
          <tr class="bank">
            <td class="center">
              <label class="inline no-padding-left">
                <input name="gid" type="checkbox" data-id="{{ $gift->id }}" class="ace ace-checkbox-2">
                <span class="lbl "> </span>
              </label>
            </td>
            <td class="center">
              <img class="img-responsive lazy gift-img" src="/assets/images/placehoder.png" data-original="{{$gift->image}}"/>
            </td>
            <td class="align-middle smaller-80">{{$gift->name}}</td>
            <td class="center b-sign">{{$gift->price}}</td>
            <td class="center b-return">{{$gift->exchanged->count()}}</td>           
          </tr>          
        @endforeach
        </tbody>
      </table>
    </div>
    
    <div class="col-xs-12 col-md-4">
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
        <tr>
          <th class="center" style="width:30px;"> </th>
          <th class="center" style="width:55px;">图片</th>
          <th class="align-middle">礼品名称</th>
          <th class="center" style="width:45px;">积分</th>
          <th class="center" style="width:45px;">已兑</th>
        </tr>
        </thead>
        <tbody>          
          @foreach ($gifts as $i=>$gift)   
          <?php
              if($i == $paging) break;
              $gift = $gifts->shift();
          ?>
          <tr class="bank">
            <td class="center">
              <label class="inline no-padding-left">
                <input name="gid" type="checkbox" data-id="{{ $gift->id }}" class="ace ace-checkbox-2">
                <span class="lbl "> </span>
              </label>
            </td>
            <td class="center">
              <img class="img-responsive lazy gift-img" src="/assets/images/placehoder.png" data-original="{{$gift->image}}"/>
            </td>
            <td class="align-middle smaller-80">{{$gift->name}}</td>
            <td class="center b-sign">{{$gift->price}}</td>
            <td class="center b-return">{{$gift->exchanged->count()}}</td>           
          </tr>          
        @endforeach
        </tbody>
      </table>
    </div>

    <div class="col-xs-12 col-md-4">
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
        <tr>
          <th class="center" style="width:30px;"> </th>
          <th class="center" style="width:55px;">图片</th>
          <th class="align-middle">礼品名称</th>
          <th class="center" style="width:45px;">积分</th>
          <th class="center" style="width:45px;">已兑</th>
        </tr>
        </thead>
        <tbody>          
          @foreach ($gifts as $i=>$gift)  
          <tr class="bank">
            <td class="center"> 
              <label class="inline no-padding-left">
                <input name="gid" type="checkbox" data-id="{{ $gift->id }}" class="ace ace-checkbox-2">
                <span class="lbl "> </span>
              </label>
            </td>
            <td class="center">
              <img class="img-responsive lazy gift-img" src="/assets/images/placehoder.png" data-original="{{$gift->image}}"/>
            </td>
            <td class="align-middle smaller-80">{{$gift->name}}</td>
            <td class="center b-sign">{{$gift->price}}</td>
            <td class="center b-return">{{$gift->exchanged->count()}}</td>           
          </tr>          
        @endforeach
        </tbody>
      </table>
    </div>
  
  </div><!-- /.row -->

  <div class="row">
    <div class="col-xs-12 center">
      <button type="submit" class="btn btn-primary submit">
        <i class="ace-icon fa fa-check"></i>
        <span class="">确定</span>
      </button>
    </div>
  </div>

@stop

@section('javascript')
  <script src="//cdn.bootcss.com/jquery_lazyload/1.9.7/jquery.lazyload.min.js"></script>
  <script type="text/javascript">
      $(function () {

          $("#query").focus();

          $(".lazy").lazyload({
            effect : "fadeIn"
          });

          $("input:checkbox[name='gid']").on('click', function(e) {
            $("input:checkbox[name='gid']").not(this).attr("checked", false);
          });

          $(".submit").on('click', function (e) {
              var gid = $("input:checkbox[name='gid']:checked").data('id');
              var uid = $("input[name='uid']").val();
              if( gid == null || gid ==""){
                layer.msg('请选择需要兑换的礼品',{shift: -1});      
                return false;
              }            
              layer.msg('确认兑换礼品？', {
                  time: 0,
                  btn: ['确定', '取消'],
                  yes: function (index) {
                      $.post('{{route('point.gift.exchange')}}', {
                          '_token': $("input[name='_token']").attr('value'),
                          'uid': uid,
                          'gid': gid
                      }, function (data) {
                          console.log(data);
                          layer.msg(data.message, {time:1000,shift: -1}, function () {
                              if (data.status === true && data.url != null) {
                                  $(window).attr('location', data.url);
                              }
                          });

                      }, 'json').error(function (data) {
                          layer.msg(data.responseJSON.message);
                      });

                  }
              });
          });

      });
  </script>
@stop